package cn.edu.jxau.test;

import java.util.Arrays;

import cn.edu.jxau.util.ArrayList;
import cn.edu.jxau.util.List;

public class Main {

    public static void main(String[] args) {
        
        String[] arr = new String[]{"qwe","asd","qwe","asd","asdasd","qwe","xzc","zxc","zxc","qwe"};
        dedup(arr);
    }

    public static void dedup(String[] arr) {

        sort(arr);
        System.out.println(Arrays.toString(arr));
        List<String> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            String str = arr[i];
            list.addLast(str);
            int j = i;
            while (j < arr.length && str.equals(arr[j])) {
                j++;
            }
            i = j - 1;
        }
        for (String str : list) {
            System.out.println(str);
        }
    }

    /**
     * 对String数组排序
     * @param arr
     */
    public static void sort(String[] arr) {

        for (int i = 1; i < arr.length; i++) {
            int j = i;
            String temp = arr[j];
            while (j > 0 && temp.compareTo(arr[j - 1]) < 0) {
                arr[j] = arr[j - 1];
                j--;
            }
            arr[j] = temp;
        }
    }
}